package com.nt.oam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.nt.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.nt.common.annotation.Log;
import com.nt.common.core.controller.BaseController;
import com.nt.common.core.domain.AjaxResult;
import com.nt.common.enums.BusinessType;
import com.nt.oam.domain.AntServer;
import com.nt.oam.service.IAntServerService;
import com.nt.common.utils.poi.ExcelUtil;
import com.nt.common.core.page.TableDataInfo;

/**
 * 服务器信息Controller
 *
 * @author JZFeng
 * @date 2025-02-05
 */
@RestController
@RequestMapping("/oam/server" )
public class AntServerController extends BaseController {
    @Autowired
    private IAntServerService antServerService;

    /**
     * 查询服务器信息列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:server:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(AntServer antServer) {
        startPage();
        List<AntServer> list = antServerService.selectAntServerList(antServer);
        return getDataTable(list);
    }

    /**
     * 导出服务器信息列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:server:export')" )
    @Log(title = "服务器信息" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, AntServer antServer) {
        List<AntServer> list = antServerService.selectAntServerList(antServer);
        ExcelUtil<AntServer> util = new ExcelUtil<AntServer>(AntServer.class);
        util.exportExcel(response, list, "服务器信息数据" );
    }

    /**
     * 获取服务器信息详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:server:query')" )
    @GetMapping(value = "/{serverId}" )
    public AjaxResult getInfo(@PathVariable("serverId" ) Long serverId) {
        return success(antServerService.selectAntServerByServerId(serverId));
    }

    /**
     * 新增服务器信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:server:add')" )
    @Log(title = "服务器信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AntServer antServer) {
        System.out.println("开始VPN： " + antServer.getVPN());
        return toAjax(antServerService.insertAntServer(antServer));
    }

    /**
     * 修改服务器信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:server:edit')" )
    @Log(title = "服务器信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AntServer antServer) {
        return toAjax(antServerService.updateAntServer(antServer));
    }

    /**
     * 删除服务器信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:server:remove')" )
    @Log(title = "服务器信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{serverIds}" )
    public AjaxResult remove(@PathVariable Long[] serverIds) {
        return toAjax(antServerService.deleteAntServerByServerIds(serverIds));
    }

    /**
     * 非系统-获取服务器信息详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:server:query')" )
    @GetMapping(value = "/details/{serverId}" )
    public AjaxResult getServerMessage(@PathVariable("serverId" ) Long serverId) {
        return success(antServerService.selectServerMessage(serverId));
    }

    /**
     * 获取页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:server:query')")
    @GetMapping(value = "/get/isModify")
    public AjaxResult getServerModify(@RequestParam Long serverId) {

        return success(antServerService.selectServerModify(serverId));
    }

    /**
     * 修改页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:server:edit')")
    @Log(title = "服务器信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit/modify/{serverId}")
    public AjaxResult editModify(@PathVariable("serverId") Long serverId) {
        int isModify = 1;
        return toAjax(antServerService.updateServerModify(serverId,isModify));
    }

}
